package com.util.thread;

import com.entity.TeacherTable;

import javax.servlet.http.HttpServletRequest;


/**
 * 本地线程，存储当前登录用户信息
 *
 * @Version 1.0.0
 * @date 2021/10/15 10:28
 **/
public class LocalThreadUtils {
	private static final ThreadLocal<TeacherTable> USER_THREAD_LOCAL = new ThreadLocal<TeacherTable>();

	private static final ThreadLocal<HttpServletRequest> HTTP_SERVLET_REQUEST_THREAD_LOCAL = new ThreadLocal<HttpServletRequest>();

	public static void add(TeacherTable user) {
		USER_THREAD_LOCAL.set(user);
	}

	public static void add(HttpServletRequest request) {
		HTTP_SERVLET_REQUEST_THREAD_LOCAL.set(request);
	}

	public static TeacherTable getCurrentUser() {
		return USER_THREAD_LOCAL.get();
	}

	public static HttpServletRequest getCurrentRequest() {
		return HTTP_SERVLET_REQUEST_THREAD_LOCAL.get();
	}

	public static void remove() {
		USER_THREAD_LOCAL.remove();
		HTTP_SERVLET_REQUEST_THREAD_LOCAL.remove();
	}
}
